package com.ncloud.resman.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.entity.SwitchVlan;

@Mapper
public interface SwitchVlanMapper{
	@Select("select vlan_id,device_id,vlan_code,ip_segment,purpose,"
			+ "CONCAT(create_user,'') as create_user,"
			+ "date_format(create_date, '%Y-%m-%d %H:%i:%s' ) as create_date, "
			+ "CONCAT(update_user,'') as update_user, "
			+ "date_format(update_date, '%Y-%m-%d %H:%i:%s' ) as update_date, remarks "
			+ "from res_switch_vlan where device_id=#{deviceId} ")
	@Results({
		@Result(column="vlan_id",property="vlanId"),@Result(column="device_id",property="deviceId"),
		@Result(column="vlan_code",property="vlanCode"),@Result(column="ip_segment",property="ipSegment"),
		@Result(column="purpose",property="purpose"),
		@Result(column="create_user",property="createUser"),@Result(column="create_date",property="createDate"),
		@Result(column="update_user",property="updateUser"),@Result(column="update_date",property="updateDate"),
		@Result(column="remarks",property="remarks")})
	List<JSONObject> getSwitchVlanInfo(Long deviceId);
	
	@Insert(value = "INSERT INTO res_switch_vlan (vlan_id, device_id, vlan_code, ip_segment, purpose, create_user, create_date, remarks) "
			+ "values(#{vlanId},#{deviceId},#{vlanCode},#{ipSegment},#{purpose},#{createUser},#{createDate},#{remarks})")
    public int insertSwitchVlan(SwitchVlan switchVlan);
	
	@Update(value = "UPDATE res_switch_vlan SET vlan_code = #{vlanCode}, ip_segment = #{ipSegment}, purpose = #{purpose}, "
			+ "update_user = #{updateUser}, update_date = #{updateDate}, remarks = #{remarks} WHERE vlan_id = #{vlanId}")
    public int updateSwitchVlan(SwitchVlan switchVlan);
	
	@Delete(value = "delete from res_switch_vlan WHERE vlan_id = #{vlanId}")
    public int deleteSwitchVlan(Long vlanId);
}
